__author__ = """Zach Seifts <zach.seifts@gmail.com>"""
__docformat__ = 'plaintext'

from Products.CMFCore.utils import getToolByName
from Products.ExternalMethod.ExternalMethod import ExternalMethod

def installWorkflows(self, package, out):
    """Install the custom workflows for this product."""

    productname = 'synchronicity'
    workflowTool = getToolByName(self, 'portal_workflow')

    ourProductWorkflow = ExternalMethod('temp', 'temp',
                                        productname+'.'+'ProjectWorkFlow',
                                        'createProjectWorkFlow')
    workflow = ourProductWorkflow(self, 'ProjectWorkFlow')
    if 'ProjectWorkFlow' in workflowTool.listWorkflows():
        print >> out, 'ProjectWorkFlow already in workflows.'
    else:
        workflowTool._setObject('ProjectWorkFlow', workflow)
    workflowTool.setChainForPortalTypes(['Project'], workflow.getId())

    ourProductWorkflow = ExternalMethod('temp', 'temp',
                                        productname+'.'+'TaskWorkFlow',
                                        'createTaskWorkFlow')
    workflow = ourProductWorkflow(self, 'TaskWorkFlow')
    if 'TaskWorkFlow' in workflowTool.listWorkflows():
        print >> out, 'TaskWorkFlow already in workflows.'
    else:
        workflowTool._setObject('TaskWorkFlow', workflow)
    workflowTool.setChainForPortalTypes(['Task'], workflow.getId())

    ourProductWorkflow = ExternalMethod('temp', 'temp',
                                        productname+'.'+'ObjectiveWorkFlow',
                                        'createObjectiveWorkFlow')
    workflow = ourProductWorkflow(self, 'ProjectWorkFlow')
    if 'ProjectWorkFlow' in workflowTool.listWorkflows():
        print >> out, 'ObjectiveWorkFlow already in workflows.'
    else:
        workflowTool._setObject('ProjectWorkFlow', workflow)
    workflowTool.setChainForPortalTypes(['Objective'], workflow.getId())

    return workflowTool

def uninstallWorkflows(self, package, out):
    """Deinstall the workflows.

    This code doesn't really do anything, but you can place custom
    code here in the protected section.
    """

    pass
